


function tmp_blink_data(sb)

gavgdir = '/home/predatt/anatod/ISI/MEG/GAVG';
cd(gavgdir)
load subjname
load dataset

rootdir = '/home/predatt/anatod/ISI';
datadir = '/home/predatt/anatod/ISI/raw'; 

infofile = strcat(subjname{sb},'_datainfo.mat'); 
subdir = fullfile(rootdir,'MEG',subjname{sb}); 
cd(subdir);
load(infofile)
cd(datadir)
fprintf('Processing subject %s... \n', subjname{sb});

    % preprocess
        cfg = [];         
        cfg = datainfo.basicinfo;
        cfg.trl = datainfo.trl;
        cfg.continuous = 'yes';
        cfg.channel = {'MEG'};
        
        data = ft_preprocessing(cfg);

        % quickly redo ICA
        cfg = [];
        cfg.unmixing     = datainfo.comp.topo;
        cfg.topolabel    = datainfo.comp.topolabel;
        comp_data        = ft_componentanalysis(cfg, data); 
  
    % remove unwanted components
        cfg = [];
        cfg.component = datainfo.comp.artifact; 
        data = ft_rejectcomponent(cfg, comp_data);
        clear comp_data
       
        cfg = [];   
        cfg.continuous = 'yes';
        cfg.channel = {'MEG'};
        cfg.bpfilter    = 'yes';
        cfg.bpfilttype  = 'but';
        cfg.bpfreq      = [1 15];
        cfg.bpfiltord   = 3;
        cfg.rectify     = 'yes';

        blinkdata = ft_preprocessing(cfg,data);
        
        
datafile = strcat(subjname{sb},'_blink_data.mat'); 
cd(subdir);

save(datafile,'blinkdata');

clear data blinkdata

% end
        
end


% disp(sb)